<?php

class User_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}

	function insert_user($response) {
		if(count($this->get_user($response['user_id'])) > 0 ){
			return true;
		}
		
		$sql = "INSERT INTO user (fb_id, email, date_created) VALUES (?, ?, NOW())";		
		$result = $this->db->query($sql, array($response['user_id'], $response['registration']['email']));
		return $result;
	}

	function get_user($fb_id) {
		$sql = "SELECT * FROM user WHERE fb_id = ? AND is_deleted = 0";
		$query = $this->db->query($sql, $fb_id);
			
		$data = array();
		if($query->num_rows() > 0){
			$data = $query->row_array();				
		}
		return $data;
	}
}
?>